package tmt.usercenter.web.plugin.editormodel;

import com.tmt.helper.ReflectHelper;
import com.tmt.jpafieldvalueconvert.JpaFieldValueConvert;
import com.tmt.jpafieldvalueconvert.impl.FileUrlFieldConverter;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Optional;

/**
 * Created by ThreeManTeam on 2017/6/6.
 */
public class EditorModelHelper {

    public static <T> Field findFirstFileField(Class<T> clazz){
        List<Field> fieldList = ReflectHelper.findAllFieldByAnnotation(clazz, JpaFieldValueConvert.class, -1);
        Optional optional = fieldList.stream().filter(x->
                x.getAnnotation(JpaFieldValueConvert.class).converter().getName().equals(FileUrlFieldConverter.class.getName()))
                .findFirst();
        if (optional.isPresent())
            return (Field) optional.get();

        return null;
    }
}
